﻿<div ng-controller="ManagementDayC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">日销售底表</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">
                    <a class="btn btn-sm btn-default" href="../api/Report/ExpManagementDay?createTime={{qTime.format('yyyy-MM-dd')}}&dept={{dept.Id}}">
                        <i class="fa fa-cloud-download text"></i>
                        <span class="text">全部导出</span>
                    </a>
                </div>
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 input-group">
                    <span class="input-group-addon">查询日期</span>
                    <input type="date" class="form-control" placeholder="按日期查找" ng-model="qTime">
                    <span class="input-group-addon">事业部</span>
                    <select class="form-control" placeholder="按事业部查找" ng-options=" x.Name for x in arr track by x.Id" ng-model="dept"></select>
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="find()">查找</button>
                    </span>
                </div>
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light table-bordered" style="width:150%">
                    <thead>
                        <tr>
                            <th width="80px" style="text-align: center;">日期</th>
                            <th width="120px" style="text-align: center;">客户名称</th>
                            <th width="150px" style="text-align: center;">户头</th>
                            <th width="500px" style="text-align: center;">品种/规格</th>
                            <th width="100px" style="text-align: center;">销售重量</th>
                            <th width="100px" style="text-align: center;">销售价格</th>
                            <th width="100px" style="text-align: center;">销售金额</th>
                            <th width="100px" style="text-align: center;">车号</th>
                            <th width="120px" style="text-align: center;">目的地</th>
                            <th width="120px" style="text-align: center;">不冲账运费</th>
                            <th width="120px" style="text-align: center;">冲账运费</th>
                            <th width="120px" style="text-align: center;">供货厂家</th>
                            <th width="150px" style="text-align: center;">库房</th>
                            <th width="150px" style="text-align: center;">备注</th>
                            <th width="150px" style="text-align: center;">事业部</th>
                            <th width="120px" style="text-align: center;">客户经理</th>
                            <th width="100px" style="text-align: center;">状态</th>
                        </tr>
                    </thead>
                    <tbody ng-repeat="ord in orders">
                        <tr ng-repeat="item in ord.CommodityInfos">
                            <td>{{ord.CreateTime | DIYData:"MM-dd"}}</td>
                            <td>{{ord.Customer.ShortName}}</td>
                            <td>{{ord.Account.Name}}</td>
                            <td>{{item.CommodityFillName}}</td>
                            <td>{{item.Weight | number:3}}</td>
                            <td>{{(item.Price - ord.UnitDiscount - ord.ApplyDiscount) | number:2}}</td>
                            <td>{{ord.Total | number:2}}</td>
                            <td>{{ord.VehicleInfos}}</td>
                            <td>{{ord.District.FillName}}</td>
                            <td><span ng-if="!ord.IsPublicDelivery">{{(ord.DeliveryPrice * item.Weight) | number:2}}</span></td>
                            <td><span ng-if="ord.IsPublicDelivery">{{(ord.DeliveryPrice * item.Weight) | number:2}}</span></td>
                            <td>{{ord.Provider.Supplier.Brand}}</td>
                            <td>{{ord.Provider.Name}}</td>
                            <td>{{ord.Remarks}}</td>
                            <td>{{ord.Creater.Department.Name}}</td>
                            <td>{{ord.Creater.Name}}</td>
                            <td ng-if="ord.State == 0">待确认</td>
                            <td ng-if="ord.State == 1">驻厂确认</td>
                            <td ng-if="ord.State == 2">已发货<span ng-if="item.IsSettlement">,已结算</span></td>
                            <td ng-if="ord.State == 3">已收货</td>
                            <td ng-if="ord.State == 4">已结算</td>
                            <td ng-if="ord.State == 5">完结</td>
                            <td ng-if="ord.State == 6">取消</td>
                            <td ng-if="ord.State == 7">审核通过</td>
                            <td ng-if="ord.State == 8">已退货</td>
                            <td ng-if="ord.State == 9">已退款</td>
                        </tr>
                    </tbody>
                </table>
                <div class="row text-center">
                    <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app') //锁价单列表控制器
    //计划单列表控制器
    .controller("ManagementDayC", function ($scope, $state, $http) {
        $scope.pageData = {};
        $scope.pageData.Page = 1;
        $scope.qTime = new Date();
        $scope.dept = "";
        $scope.pageData.Rows = $scope.defPageRows;


        $http.get('../api/Department')
      .success(function (res) {
          $scope.departments = res.Data;
          $scope.traverseTree($scope.departments);
          $scope.dept = $scope.departments[0].Item2;
      });


        $scope.arr = [];
        $scope.traverseTree = function (node) {
           
            for (var i = 0; i < node.length; i++) {
                var empty = '　└─';
                for (var j = 1; j < node[i].Item1; j++) {
                    empty = '　　' + empty;
                }
                if (i != 0) {
                    node[i].Item2.Name = empty + node[i].Item2.Name;
                } else {
                    node[i].Item2.Name = '　' + node[i].Item2.Name;
                }
                $scope.arr.push(node[i].Item2);
            }

            $scope.arr[0].selected = true;
        };

        $scope.getData = function (p, r) {
            if (p) {
                p = p < 1 ? 1 : p;
            } else p = 1;
            if (r) {
            } else r = $scope.defPageRows;
            $http.get("../api/Report/ManagementDay", { params: { page: p, rows: r, createTime: $scope.qTime.format('yyyy-MM-dd'), dept: $scope.dept.Id } })
                    .then(function (res) {
                        $scope.orders = res.data.Data;
                        $scope.pageData = res.data;
                    })
                    .then(function (error) {
                        if (error) {
                            alert("数据获取失败");
                        }
                    });
        };
        $scope.find = function () {
            $scope.getData(1, $scope.rows);
        };
        //加载数据
        $scope.getData($scope.page, $scope.rows);
    })
</script>